package com.bracketbird.client.gui;


import com.bracketbird.client.*;
import com.bracketbird.client.event.*;
import com.bracketbird.client.gui.club.*;
import com.bracketbird.client.gui.club.home.*;
import com.bracketbird.client.gui.club.tournament.*;
import com.bracketbird.clientcore.appcontrol.*;
import com.bracketbird.clientcore.gui.*;
import com.bracketbird.clientcore.style.*;

/**
 *
 */
public class MenuPanel extends AbstractMenuPanel {

    private HorizontalComponent content;

    public MenuPanel() {
        EventManager.eventBus.addHandler(UserStateChangedEvent.TYPE,
                new UserStateChangedHandler() {
                    public void onChange(UserStateChangedEvent event) {
                        updateMenu();
                    }
                });
    }

    public void addSectionTitle(String title) {
        //ignore
    }

    protected void add(MenuComponent mc) {

    }


    private void updateMenu() {
        UserManager um = UserManager.getInstance();
        if (um.isInTransistionLoggedOut()) {
            for (MenuComponent m : getAllMenues()) {
                m.setVisible(false);
            }
        }
        //logged in
        else {
            if (um.isInTransitionLoggedIn()) {
                for (MenuComponent m : getAllMenues()) {
                    m.setVisible(false);
                }
            }
            else {//in club transistion
                for (MenuComponent m : getAllMenues()) {
                    m.setVisible(true);
                }
            }
        }
    }


    public HorizontalComponent getPanel() {
        if (content == null) {
            content = new HorizontalComponent();
            setup(content, ClubHomePageController.getInstance());
            setup(content, ForumPageController.getInstance());
            setup(content, TournamentsPageController.getInstance());
            setup(content, StatisticsResultTournamentPageController.getInstance());
            setup(content, ArchivePageController.getInstance());
            setup(content, AdminPageController.getInstance());

            SimplePanelComponent sp = new SimplePanelComponent();
            content.add(sp, new TextLayout(null, "100%"));

            content.setStyleName("menu");

        }
        return content;
    }

    private void setup(HorizontalComponent hc, PageController pc) {
        addMenuItem(pc);
        hc.add(pc.getMenu(), new Layout17(0, 0, 0, 0, "80%", null, null, Vertical.BOTTOM));
        //pc.getMenu().setVisible(false);
    }


}